package com.lucifer.treasure.datagen;

import com.lucifer.treasure.registry.LuciferTreasureTags;
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricDynamicRegistryProvider;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
import net.minecraft.component.EnchantmentEffectComponentTypes;
import net.minecraft.component.type.AttributeModifierSlot;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentLevelBasedValue;
import net.minecraft.enchantment.effect.AttributeEnchantmentEffect;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.util.Identifier;

import java.util.concurrent.CompletableFuture;

public class LuciferTreasureDataGenerator implements DataGeneratorEntrypoint {

    @Override
    public void onInitializeDataGenerator(FabricDataGenerator generator) {
        FabricDataGenerator.Pack pack = generator.createPack();
        pack.addProvider(EnchantmentGenerator::new);
        pack.addProvider(ItemTagGenerator::new);
    }

    private static class EnchantmentGenerator extends FabricDynamicRegistryProvider {

        public EnchantmentGenerator(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> registriesFuture) {
            super(output, registriesFuture);
        }

        @Override
        protected void configure(RegistryWrapper.WrapperLookup registries, Entries entries) {
            var itemLookup = registries.getWrapperOrThrow(RegistryKeys.ITEM);

            // 1. 自动熔炼附魔 - 挖掘工具
            var autoSmeltId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "auto_smelt"));
            Enchantment.Builder autoSmelt = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.MINING_ENCHANTABLE),
                                    3, 1,
                                    Enchantment.leveledCost(20, 0),
                                    Enchantment.leveledCost(40, 0),
                                    3, AttributeModifierSlot.MAINHAND
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "auto_smelt"),
                                    EntityAttributes.GENERIC_LUCK,
                                    EnchantmentLevelBasedValue.constant(1.0F),
                                    EntityAttributeModifier.Operation.ADD_VALUE)
                    );
            entries.add(autoSmeltId, autoSmelt.build(autoSmeltId.getValue()));

            // 2. 磁力附魔 - 挖掘工具
            var magnetId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "magnet"));
            Enchantment.Builder magnet = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.MINING_ENCHANTABLE),
                                    6, 3,
                                    Enchantment.leveledCost(8, 8),
                                    Enchantment.leveledCost(30, 10),
                                    2, AttributeModifierSlot.MAINHAND
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "magnet_range"),
                                    EntityAttributes.GENERIC_LUCK,
                                    EnchantmentLevelBasedValue.linear(1.0F),
                                    EntityAttributeModifier.Operation.ADD_VALUE)
                    );
            entries.add(magnetId, magnet.build(magnetId.getValue()));

            // 3. 自动步行附魔 - 靴子
            var stepId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "step"));
            Enchantment.Builder step = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.FOOT_ARMOR_ENCHANTABLE),
                                    3, 1,
                                    Enchantment.leveledCost(20, 0),
                                    Enchantment.leveledCost(50, 0),
                                    3, AttributeModifierSlot.FEET
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "step"),
                                    EntityAttributes.GENERIC_MOVEMENT_SPEED,
                                    EnchantmentLevelBasedValue.constant(0.02F),
                                    EntityAttributeModifier.Operation.ADD_MULTIPLIED_BASE)
                    );
            entries.add(stepId, step.build(stepId.getValue()));

            // 4. 连锁挖掘附魔 - 挖掘工具
            var excavationId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "excavation"));
            Enchantment.Builder excavation = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.MINING_ENCHANTABLE),
                                    1, 3,
                                    Enchantment.leveledCost(25, 10),
                                    Enchantment.leveledCost(75, 10),
                                    8, AttributeModifierSlot.MAINHAND
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "excavation"),
                                    EntityAttributes.GENERIC_ATTACK_SPEED,
                                    EnchantmentLevelBasedValue.linear(0.1F),
                                    EntityAttributeModifier.Operation.ADD_MULTIPLIED_BASE)
                    );
            entries.add(excavationId, excavation.build(excavationId.getValue()));

            // 5. 方块延伸附魔 - 武器
            var reachId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "reach"));
            Enchantment.Builder reach = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.WEAPON_ENCHANTABLE),
                                    4, 3,
                                    Enchantment.leveledCost(12, 8),
                                    Enchantment.leveledCost(37, 8),
                                    2, AttributeModifierSlot.MAINHAND
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "reach"),
                                    EntityAttributes.PLAYER_ENTITY_INTERACTION_RANGE,
                                    EnchantmentLevelBasedValue.linear(0.5F),
                                    EntityAttributeModifier.Operation.ADD_VALUE)
                    );
            entries.add(reachId, reach.build(reachId.getValue()));

            // 6. 生命汲取附魔 - 武器
            var lifeLeechId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "life_leech"));
            Enchantment.Builder lifeLeech = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.WEAPON_ENCHANTABLE),
                                    3, 3,
                                    Enchantment.leveledCost(15, 8),
                                    Enchantment.leveledCost(45, 8),
                                    3, AttributeModifierSlot.MAINHAND
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "life_leech"),
                                    EntityAttributes.GENERIC_ATTACK_DAMAGE,
                                    EnchantmentLevelBasedValue.linear(0.5F),
                                    EntityAttributeModifier.Operation.ADD_VALUE)
                    );
            entries.add(lifeLeechId, lifeLeech.build(lifeLeechId.getValue()));

            // 7. 斩首附魔 - 武器
            var beheadingId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "beheading"));
            Enchantment.Builder beheading = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.WEAPON_ENCHANTABLE),
                                    2, 3,
                                    Enchantment.leveledCost(20, 10),
                                    Enchantment.leveledCost(50, 10),
                                    4, AttributeModifierSlot.MAINHAND
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "beheading"),
                                    EntityAttributes.GENERIC_LUCK,
                                    EnchantmentLevelBasedValue.linear(0.5F),
                                    EntityAttributeModifier.Operation.ADD_VALUE)
                    );
            entries.add(beheadingId, beheading.build(beheadingId.getValue()));

            // 8. 经验提升附魔 - 武器、工具、弓
            var experienceBoostId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "experience_boost"));
            Enchantment.Builder experienceBoost = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.WEAPON_ENCHANTABLE),
                                    4, 3,
                                    Enchantment.leveledCost(15, 10),
                                    Enchantment.leveledCost(45, 12),
                                    2, AttributeModifierSlot.MAINHAND
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "experience_boost"),
                                    EntityAttributes.GENERIC_LUCK,
                                    EnchantmentLevelBasedValue.linear(0.5F),
                                    EntityAttributeModifier.Operation.ADD_VALUE)
                    );
            entries.add(experienceBoostId, experienceBoost.build(experienceBoostId.getValue()));

            // 9. 成长附魔 - 锄头
            var growthId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "growth"));
            Enchantment.Builder growth = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.HOES),
                                    3, 3,
                                    Enchantment.leveledCost(15, 9),
                                    Enchantment.leveledCost(45, 9),
                                    2, AttributeModifierSlot.MAINHAND
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "growth"),
                                    EntityAttributes.GENERIC_LUCK,
                                    EnchantmentLevelBasedValue.linear(0.3F),
                                    EntityAttributeModifier.Operation.ADD_VALUE)
                    );
            entries.add(growthId, growth.build(growthId.getValue()));

            // 10. 养蜂人附魔 - 头盔
            var beekeeperId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "beekeeper"));
            Enchantment.Builder beekeeper = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.HEAD_ARMOR_ENCHANTABLE),
                                    4, 2,
                                    Enchantment.leveledCost(20, 10),
                                    Enchantment.leveledCost(60, 10),
                                    3, AttributeModifierSlot.HEAD
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "beekeeper"),
                                    EntityAttributes.GENERIC_LUCK,
                                    EnchantmentLevelBasedValue.linear(0.5F),
                                    EntityAttributeModifier.Operation.ADD_VALUE)
                    );
            entries.add(beekeeperId, beekeeper.build(beekeeperId.getValue()));

            // 11. 毒液附魔 - 武器  
            var venomId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "venom"));
            Enchantment.Builder venom = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.WEAPON_ENCHANTABLE),
                                    5, 3,
                                    Enchantment.leveledCost(10, 8),
                                    Enchantment.leveledCost(35, 8),
                                    2, AttributeModifierSlot.MAINHAND
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "venom"),
                                    EntityAttributes.GENERIC_ATTACK_DAMAGE,
                                    EnchantmentLevelBasedValue.linear(0.5F),
                                    EntityAttributeModifier.Operation.ADD_VALUE)
                    );
            entries.add(venomId, venom.build(venomId.getValue()));

            // 12. 缴械附魔 - 武器
            var disarmId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "disarm"));
            Enchantment.Builder disarm = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.WEAPON_ENCHANTABLE),
                                    3, 3,
                                    Enchantment.leveledCost(18, 10),
                                    Enchantment.leveledCost(45, 10),
                                    3, AttributeModifierSlot.MAINHAND
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "disarm"),
                                    EntityAttributes.GENERIC_ATTACK_SPEED,
                                    EnchantmentLevelBasedValue.linear(0.1F),
                                    EntityAttributeModifier.Operation.ADD_MULTIPLIED_BASE)
                    );
            entries.add(disarmId, disarm.build(disarmId.getValue()));

            // 13. 多重射击附魔 - 弓
            var multibowId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "multibow"));
            Enchantment.Builder multibow = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.BOW_ENCHANTABLE),
                                    2, 3,
                                    Enchantment.leveledCost(25, 15),
                                    Enchantment.leveledCost(70, 15),
                                    4, AttributeModifierSlot.MAINHAND
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "multibow"),
                                    EntityAttributes.GENERIC_ATTACK_DAMAGE,
                                    EnchantmentLevelBasedValue.linear(0.3F),
                                    EntityAttributeModifier.Operation.ADD_VALUE)
                    );
            entries.add(multibowId, multibow.build(multibowId.getValue()));

            // 14. 快速拉弓附魔 - 弓
            var quickdrawId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "quickdraw"));
            Enchantment.Builder quickdraw = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.BOW_ENCHANTABLE),
                                    5, 3,
                                    Enchantment.leveledCost(12, 8),
                                    Enchantment.leveledCost(40, 8),
                                    4, AttributeModifierSlot.MAINHAND
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "quickdraw"),
                                    EntityAttributes.GENERIC_ATTACK_SPEED,
                                    EnchantmentLevelBasedValue.linear(0.15F),
                                    EntityAttributeModifier.Operation.ADD_MULTIPLIED_BASE)
                    );
            entries.add(quickdrawId, quickdraw.build(quickdrawId.getValue()));

            // 15. 多重跳跃附魔 - 靴子
            var multijumpId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "multijump"));
            Enchantment.Builder multijump = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.FOOT_ARMOR_ENCHANTABLE),
                                    2, 5,
                                    Enchantment.leveledCost(20, 12),
                                    Enchantment.leveledCost(65, 12),
                                    3, AttributeModifierSlot.FEET
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "multijump"),
                                    EntityAttributes.GENERIC_SAFE_FALL_DISTANCE,
                                    EnchantmentLevelBasedValue.linear(2.0F),
                                    EntityAttributeModifier.Operation.ADD_VALUE)
                    );
            entries.add(multijumpId, multijump.build(multijumpId.getValue()));

            // 16. 旅行者附魔 - 靴子
            var travellerId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "traveller"));
            Enchantment.Builder traveller = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.FOOT_ARMOR_ENCHANTABLE),
                                    5, 3,
                                    Enchantment.leveledCost(15, 8),
                                    Enchantment.leveledCost(40, 8),
                                    4, AttributeModifierSlot.FEET
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "traveller"),
                                    EntityAttributes.GENERIC_MOVEMENT_SPEED,
                                    EnchantmentLevelBasedValue.linear(0.1F),
                                    EntityAttributeModifier.Operation.ADD_MULTIPLIED_BASE)
                    );
            entries.add(travellerId, traveller.build(travellerId.getValue()));

            // 17. 最后一击附魔 - 胸甲
            var laststandId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "laststand"));
            Enchantment.Builder laststand = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.CHEST_ARMOR_ENCHANTABLE),
                                    2, 3,
                                    Enchantment.leveledCost(25, 15),
                                    Enchantment.leveledCost(70, 15),
                                    3, AttributeModifierSlot.CHEST
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "laststand"),
                                    EntityAttributes.GENERIC_ATTACK_DAMAGE,
                                    EnchantmentLevelBasedValue.linear(1.0F),
                                    EntityAttributeModifier.Operation.ADD_VALUE)
                    );
            entries.add(laststandId, laststand.build(laststandId.getValue()));

            // 18. 阴暗诅咒附魔 - 任意盔甲部件  
            var gloomCurseId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "gloom_curse"));
            Enchantment.Builder gloomCurse = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.ARMOR_ENCHANTABLE), // 改为任意盔甲
                                    3, 3,
                                    Enchantment.leveledCost(20, 12),
                                    Enchantment.leveledCost(65, 12),
                                    3, AttributeModifierSlot.ARMOR // 普通权重
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "gloom_curse"),
                                    EntityAttributes.GENERIC_ATTACK_DAMAGE,
                                    EnchantmentLevelBasedValue.linear(0.5F), // 攻击力加成
                                    EntityAttributeModifier.Operation.ADD_VALUE)
                    );
            entries.add(gloomCurseId, gloomCurse.build(gloomCurseId.getValue()));

            // 19. 末影珍珠附魔 - 武器
            var enderPearlId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "ender_pearl"));
            Enchantment.Builder enderPearl = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.WEAPON_ENCHANTABLE),
                                    3, 3,
                                    Enchantment.leveledCost(20, 10),
                                    Enchantment.leveledCost(50, 10),
                                    3, AttributeModifierSlot.MAINHAND
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "ender_pearl"),
                                    EntityAttributes.GENERIC_MOVEMENT_SPEED,
                                    EnchantmentLevelBasedValue.linear(0.05F),
                                    EntityAttributeModifier.Operation.ADD_MULTIPLIED_BASE)
                    );
            entries.add(enderPearlId, enderPearl.build(enderPearlId.getValue()));

            // 20. 稳固附魔 - 工具
            var steadyId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "steady"));
            Enchantment.Builder steady = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.MINING_ENCHANTABLE),
                                    5, 1,
                                    Enchantment.leveledCost(18, 0),
                                    Enchantment.leveledCost(45, 0),
                                    4, AttributeModifierSlot.MAINHAND
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "steady"),
                                    EntityAttributes.GENERIC_ATTACK_SPEED,
                                    EnchantmentLevelBasedValue.constant(0.05F),
                                    EntityAttributeModifier.Operation.ADD_MULTIPLIED_BASE)
                    );
            entries.add(steadyId, steady.build(steadyId.getValue()));

            // 21. 方块范围扩展附魔 - 胸甲
            var blockReachId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "block_reach"));
            Enchantment.Builder blockReach = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(ItemTags.CHEST_ARMOR_ENCHANTABLE),
                                    4, 3,
                                    Enchantment.leveledCost(16, 8),
                                    Enchantment.leveledCost(45, 8),
                                    4, AttributeModifierSlot.CHEST
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "block_reach"),
                                    EntityAttributes.PLAYER_BLOCK_INTERACTION_RANGE,
                                    EnchantmentLevelBasedValue.linear(0.5F),
                                    EntityAttributeModifier.Operation.ADD_VALUE)
                    );
            entries.add(blockReachId, blockReach.build(blockReachId.getValue()));

            // 22. 御剑术附魔 - 宝藏附魔（只能通过钓鱼和村民交易获得）
            var swordAuraId = RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", "sword_aura"));

            /* 御剑术附魔 - 宝藏附魔
             *
             * 🏆 宝藏附魔特性（通过手动编辑JSON实现）：
             * - JSON中添加了 "primary_items": [] 确保不在附魔台出现
             * - 只能通过钓鱼、村民交易、命令等方式获得
             * - 支持所有武器类型，包括三叉戟、弓、弩等
             * - 最大等级30，与原版顶级附魔一致
             *
             * 🗡️ 支持的武器类型：
             * - 所有 #minecraft:enchantable/weapon 标签内的物品
             * - 剑、斧头、钝器、三叉戟、弓、弩等
             *
             * 🎮 获取方式：
             * - ✅ 钓鱼：稀有收获
             * - ✅ 村民交易：图书管理员等
             * - ✅ 命令：/give @s sword[enchantments={sword_aura:30}]
             * - ❌ 附魔台：不会出现（宝藏附魔）
             *
             * 🎨 独特的粒子效果系统：
             * - 剑类：附魔粒子（紫色） + 护手光环
             * - 斧头类：暴击粒子（金色） + 护手光环
             * - 三叉戟：气泡粒子（蓝色） + 护手光环
             * - 钓鱼竿：钓鱼粒子（绿色） + 护手光环
             * - 弓弩类：法术粒子（青色） + 护手光环
             * - 工具类：爆炸粒子（红色） + 护手光环
             * - 箭类：末影粒子（黑色） + 护手光环
             * - 魔杖类：女巫粒子（橙色） + 护手光环
             * - 其他物品：基础烟雾粒子 + 护手光环
             */

            Enchantment.Builder swordAura = Enchantment.builder(
                            Enchantment.definition(
                                    itemLookup.getOrThrow(LuciferTreasureTags.Items.Enchantable.SWORD_AURA_ENCHANTABLE), // 使用注册的自定义标签
                                    5, 30, // 权重5（仅用于村民交易等），最大等级30
                                    Enchantment.leveledCost(20, 10), // 标准成本
                                    Enchantment.leveledCost(50, 15), // 标准成本
                                    3, AttributeModifierSlot.MAINHAND // 标准铁砧成本
                            )
                    )
                    .addEffect(
                            EnchantmentEffectComponentTypes.ATTRIBUTES,
                            new AttributeEnchantmentEffect(
                                    Identifier.of("lucifer_treasure", "sword_aura_power"),
                                    EntityAttributes.GENERIC_ATTACK_DAMAGE,
                                    EnchantmentLevelBasedValue.linear(1.0F),
                                    EntityAttributeModifier.Operation.ADD_VALUE)
                    );
            entries.add(swordAuraId, swordAura.build(swordAuraId.getValue()));
        }

        @Override
        public String getName() {
            return "路西法的宝藏";
        }
    }

    private static class ItemTagGenerator extends FabricTagProvider.ItemTagProvider {

        public ItemTagGenerator(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> registriesFuture) {
            super(output, registriesFuture);
        }

        @Override
        protected void configure(RegistryWrapper.WrapperLookup registries) {
            // 创建御剑术附魔支持的物品标签
            getOrCreateTagBuilder(LuciferTreasureTags.Items.Enchantable.SWORD_AURA_ENCHANTABLE)
                    // 原版武器标签
                    .addOptionalTag(ItemTags.WEAPON_ENCHANTABLE)
                    .addOptionalTag(ItemTags.ARMOR_ENCHANTABLE)
                    .addOptionalTag(ItemTags.MINING_ENCHANTABLE)
                    .addOptionalTag(ItemTags.BOW_ENCHANTABLE)
                    .addOptionalTag(ItemTags.CROSSBOW_ENCHANTABLE)
                    .addOptionalTag(ItemTags.TRIDENT_ENCHANTABLE)
                    .addOptionalTag(ItemTags.FISHING_ENCHANTABLE)
                    // 特殊物品
                    .addOptional(Identifier.of("minecraft", "stick"))
                    .addOptional(Identifier.of("minecraft", "arrow"))
                    .addOptional(Identifier.of("minecraft", "spectral_arrow"))
                    .addOptional(Identifier.of("minecraft", "tipped_arrow"))
                    .addOptional(Identifier.of("minecraft", "blaze_rod"))
                    .addOptional(Identifier.of("minecraft", "shears"))
                    .addOptional(Identifier.of("minecraft", "flint_and_steel"))
                    .addOptional(Identifier.of("minecraft", "compass"))
                    .addOptional(Identifier.of("minecraft", "diamond"))
                    .addOptional(Identifier.of("minecraft", "emerald"));
        }

        @Override
        public String getName() {
            return "路西法的宝藏 Item Tags";
        }
    }
} 